package Morning;

import java.text.Collator;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Locale;
import java.util.TreeSet;

public class TreeSetComparator {


    public static void main(String[] args) {

        TreeSet<Students> stu = new TreeSet<>(new Comparator<Students>() {
            @Override
            public int compare(Students o1, Students o2) {

                int res = (o1.getChineseScore() + o1.getMathsocer() - o2.getChineseScore() + o2.getMathsocer());


                res = res == 0 ? o1.getMathsocer() - o2.getMathsocer() : res;

                Collator instance = Collator.getInstance(Locale.CHINA);

                res = instance.compare(o1.getName(), o2.getName());
                return res;
            }
        });


        stu.add(new Students("张三", 100, 89));
        stu.add(new Students("李四", 99, 89));
        stu.add(new Students("王五", 89, 99));
        stu.add(new Students("赵六", 98, 100));

        Iterator<Students> iterator = stu.iterator();

        while (iterator.hasNext()) {
            System.out.println(iterator.next());

        }

    }
}
